package com.lkxicy.wos.controller;


import com.lkxicy.wos.pojo.entity.Holiday;
import com.lkxicy.wos.service.HolidayService;
import com.lkxicy.wos.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lkxicy
 * @since 2020-11-30
 */
@RestController
@RequestMapping("/wos/v1/holiday/")
public class HolidayController {

    @Autowired
    private HolidayService holidayService;

    /**
     * 员工请假
     * @return
     */
    @PostMapping("askForHoliday")
    public Response askForHoliday(@RequestParam("staffNumber") String staffNumber,
                                  @RequestParam("beginTime") Date beginTime,
                                  @RequestParam("endTime") Date endTime,
                                  @RequestParam("holidayExplain") String holidayExplain){
        Holiday holiday=new Holiday();
        holiday.setStaffNumber(staffNumber);
        holiday.setBeginTime(beginTime);
        holiday.setEndTime(endTime);
        holiday.setHolidayExplain(holidayExplain);
        return Response.success(holidayService.askForHoliday(holiday));
    }

    /**
     * 查询最近五条员工请假记录
     * @param staffNumber
     * @return
     */
    @GetMapping("searchOneHolidayRecord")
    public Response searchOneHolidayRecord(@RequestParam("staffNumber") String staffNumber){
        return Response.success(holidayService.searchOneHolidayRecord(staffNumber));
    }

    /**
     * 准假或驳回，传1则准假，0则驳回
     * 这里有点麻烦，要传从后端拿到的 数据库内的自增id 和 批准与否 字段
     * @return
     */
    @PutMapping("permitOrRejectHoliday")
    public Response permitOrRejectHoliday(@RequestParam("id") int id,
                                          @RequestParam("approval") int approval){
        return Response.success(holidayService.permitOrRejectHoliday(id,approval));
    }


    /**
     * 查询全部还未处理的请假申请
     * @return
     */
    @GetMapping("searchAllHolidayApply")
    public Response searchAllHolidayApply(){
        return Response.success(holidayService.searchAllHolidayApply());
    }

    /**
     * 保留的测试接口
     * @return
     */
    @RequestMapping("hello")
    public String hello(){
        return "hello";
    }

}

